package com.ww.springboot.boot.javabase.proxy.demo2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 描述：
 *
 * @author wanwei
 * @since 2021-07-16 14:29
 */
public class PluginTest implements InvocationHandler {

    private InterceptorTest interceptorTest;
    private Object target;

    public PluginTest(Object target,InterceptorTest interceptorTest) {
        this.interceptorTest = interceptorTest;
        this.target = target;
    }


    public static Object wrap(Object object, InterceptorTest interceptorTest) {
        return Proxy.newProxyInstance(object.getClass().getClassLoader(), object.getClass().getInterfaces(), new PluginTest(object,interceptorTest));
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return interceptorTest.intercept(new Invocation(target, method, args));
    }
}
